
import { Commit } from "vuex"
import { ILogin } from "/@/api/type"

export interface State {
  count: number
  token: string | null
}

// 第二种写法 state:initParams()
// const initParams = () => {
//   return {
//     count:0
//   }
// }

const todoState = {
  namespaced:true,
  state:{
    count:0,
    token:""
  },
  mutations: {
    increment(state:State,count:number):void {
      state.count = count + 2 
    },
    SET_TOKEN(state:State, token:string):void {
      state.token = token 
    }
  },
  actions: {
    login(context: {commit: Commit},params:ILogin):Promise<IResponse> {
      return login(params).then((res:any) => {
        context.commit("SET_TOKEN",res.data.token)
      })
    }
  }
}
export default todoState
